<template>
  <div>
    <section class="container-login">
      <!-- <div class="container-img">
        <img src="../../../static/zcbk2.png" alt="">
      </div> -->
      <div class="wrap-login layui-anim layui-anim-up">
        <form class="login-form validate-form layui-form">
          <span class="login-form-title">注册账号</span>
          <div class="wrap-input validate-input">
            <!-- <div class="wrap-div">手机号码</div> -->
            <!-- <img src="/static/login/我 的@2x.png" class="login_img" /> -->
            <input class="input" type="tel" name="phone" lay-verify="required" v-model="user.mobile"
              placeholder="请输入手机号" />
            <span class="focus-input"></span>
            <span class="symbol-input100">
              <i class="el-icon-user" style="margin-left:-20px;font-size:20px"></i>
            </span>
          </div>

          <!-- 验证码 -->
          <div class="wrap-input validate-input">
            <!-- <div class="wrap-div">验证码</div> -->
            <!-- <img src="../../../static/login/code.png" class="login_img" style="width:20px;height:20px"/> -->
            <input class="input" type="text" name="text" v-model="user.code" autocomplete="off"
              οnfοcus="this.type='text'" style="width:160px;margin-right:5px" placeholder="请输入验证码" />
            <span class="focus-input"></span>
            <span class="symbol-input100">
              <i class="el-icon-s-promotion" style="margin-left:-20px;font-size:20px"></i>
            </span>
            <a @click="getCode" class="code">
              <div class="login_getCode">{{ codeText }}</div>
            </a>
          </div>
          <!-- QQ -->
          <!-- <div class="wrap-input validate-input">
            <div class="wrap-div">您的QQ</div>
            <input
              class="input layui-input"
              type="tel"
              name="qq"
              v-model="user.qq"
            />
            <span class="focus-input"></span>
          </div> -->

          <div class="wrap-input validate-input">
            <!-- <div class="wrap-div">密码</div> -->
            <!-- <img src="/static/login/我 的@2x.png" class="login_img" /> -->
            <input class="input layui-input" type="password" name="password" v-model="user.password"
              autocomplete="new-password" οnfοcus="this.type='password'" placeholder="请输入密码" />

            <span class="focus-input"></span>
            <span class="symbol-input100">
              <i class="el-icon-lock" style="margin-left:-20px;font-size:20px"></i>
            </span>
          </div>
          <div class="wrap-input validate-input">
            <!-- <div class="wrap-div">确认密码</div> -->
            <!-- <img src="/static/login/我 的@2x.png" class="login_img" /> -->
            <input class="input layui-input" type="password" name="password" v-model="user.re_password"
              autocomplete="new-password" οnfοcus="this.type='password'" placeholder="请确认密码" />
            <span class="focus-input"></span>
            <span class="symbol-input100">
              <i class="el-icon-lock" style="margin-left:-20px;font-size:20px"></i>
            </span>
          </div>
          <div class="text-center p-t-12 agrea_box">
            <el-checkbox v-model="agrea_checked" class="text-span"></el-checkbox>
            <div class="agrea_text">
              我阅读并同意<a href="/#/agreement">《服务政策》</a>以及<a href="/#/privacy">《隐私政策》</a>
            </div>
          </div>
          <div class="container-login-form-btn">
            <input class="login-form-btn" value="注册" :disabled="btnSubmitDisabled" type="button" lay-submit
              lay-filter="login" @click="submitFrom()" />
          </div>

          <!-- <div class="text-center p-t-136">
            <a class="txt1" href="#">免费注册</a><span>|</span><a href="#" class="txt1">忘记账号密码？</a>
          </div> -->
        </form>
      </div>
    </section>

  </div>
</template>

<script>
  export default {
    //import引入的组件需要注入到对象中才能使用
    components: {},
    data() {
      //这里存放数据
      return {
        //注册数据
        agrea_checked: false,
        user: {
          mobile: "",
          code: "",
          password: "",
          re_password: ""
        },
        share_short: "0", //上级ID
        codeText: "获取验证码",
        // 验证码定时器
        timer_code: "",
        //倒计时时间
        timer_count: 60,
        checkList: ["选中且禁用", "复选框 A"],
        btnSubmitDisabled: false,
      };
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods: {
      // 获取验证码
      getCode() {
        if (String(this.user.mobile).length != 11) {
          this.$message.error("请输入正确的手机号");
          return;
        }

        if (this.codeText != "获取验证码") {
          return;
        }

        this.timer_count = 60;
        var params = new URLSearchParams();
        params.append("mobile", String(this.user.mobile));
        params.append("event", "register");
        let that = this;
        that.$post(this.API.Sms_code, params).then(res => {
          if (res.code == 1) {
            that.timer_code = setInterval(() => {
              that.codeText = this.timer_count;
              that.timer_count--;
              if (that.timer_count < 0) {
                that.codeText = "获取验证码";
                clearInterval(that.timer_code);
              }
            }, 1000);
          }
        });
      },

      // 提交
      submitFrom() {
        if (String(this.user.mobile).length != 11) {
          this.$message.error("请输入正确的手机号");
          return;
        }
        if (String(this.user.code).length != 4) {
          this.$message.error("请输入正确的验证码");
          return;
        }
        if (String(this.user.password).length < 6) {
          this.$message.error("密码必须大于6位数");
          return;
        }
        if (String(this.user.re_password).length < 6) {
          this.$message.error("密码必须大于6位数");
          return;
        }
        if (String(this.user.re_password) != String(this.user.password)) {
          this.$message.error("两次密码输入不一致");
          return;
        }
        if (!this.agrea_checked) {
          this.$message.error("必须阅读，且同意服务协议!");
          return;
        }
        this.btnSubmitDisabled = true;
        var params = new URLSearchParams();
        params.append("mobile", String(this.user.mobile));
        params.append("code", String(this.user.code));
        params.append("password", String(this.user.password));
        params.append("share_short", String(this.share_short));
        this.$post(this.API.UserRegister, params).then(res => {
          if (res) {
            this.btnSubmitDisabled = false;
            if (res.code == 1) {
              //修改成功，跳到登录页
              this.$message.success("成功，请重新登录");
              this.$router.push({
                path: "/login",
                name: "login"
              });
              return;
            }
          }
        });
      },
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {
      var key = this.$route.params.key;
      // var key = this.$route.query.key;
      console.log(this.$route.path)
      console.log(key);
      if (key != undefined && key != "undefined") {
        this.share_short = key;
      }
      console.log(this.share_short);
    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {}
  };

</script>
<style scoped>
  html {
    margin: 0;
    padding: 0;
    overflow: hidden;
  }

  a {
    cursor: pointer;
    text-decoration: none;
  }

  .container-login {
    width: 100%;
    min-height: auto;
    padding: 15px;
    align-items: center;
    background-image: url("../../../static/login/zhucebk.jpg");
    background-color: #000;
    background-repeat: no-repeat;
    background-size: 100%;
    background-position-y: 50px;
  }

  .wrap-login {
    margin-top: 100px;
    margin-bottom: 200px;
    width: 420px;
    height: 500px;
    background: rgba(10, 10, 10, 0.9);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    left: 60vw;
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    justify-content: center;
    align-items: center;
    border: 1px solid #f9761f;
  }

  a {
    font-family: Poppins-Regular;
    font-size: 14px;
    line-height: 1.7;
    color: #666666;
    margin: 0px;
    transition: all 0.4s;
    -webkit-transition: all 0.4s;
    -o-transition: all 0.4s;
    -moz-transition: all 0.4s;
  }

  a:focus {
    outline: none !important;
  }

  /* 
  a:hover {
    color: #70a9ff;
  } */

  /* p {
    font-family: Poppins-Regular;
    font-size: 14px;
    line-height: 1.7;
    color: #666666;
    margin: 0px;
  } */

  ul,
  li {
    margin: 0px;
    list-style-type: none;
  }

  /*---------------------------------------------*/
  input {
    outline: none;
    border: none;
  }

  textarea {
    outline: none;
    border: none;
  }

  textarea:focus,
  input:focus {
    border-color: transparent !important;
  }

  input:focus::-webkit-input-placeholder {
    color: transparent;
  }

  input:focus:-moz-placeholder {
    color: transparent;
  }

  input:focus::-moz-placeholder {
    color: transparent;
  }

  input:focus:-ms-input-placeholder {
    color: transparent;
  }

  textarea:focus::-webkit-input-placeholder {
    color: transparent;
  }

  textarea:focus:-moz-placeholder {
    color: transparent;
  }

  textarea:focus::-moz-placeholder {
    color: transparent;
  }

  textarea:focus:-ms-input-placeholder {
    color: transparent;
  }

  input::-webkit-input-placeholder {
    color: #999999;
  }

  input:-moz-placeholder {
    color: #999999;
  }

  input::-moz-placeholder {
    color: #999999;
  }

  input:-ms-input-placeholder {
    color: #999999;
  }

  textarea::-webkit-input-placeholder {
    color: #999999;
  }

  textarea:-moz-placeholder {
    color: #999999;
  }

  textarea::-moz-placeholder {
    color: #999999;
  }

  textarea:-ms-input-placeholder {
    color: #999999;
  }

  /*---------------------------------------------*/
  button {
    outline: none !important;
    border: none;
    background: transparent;
  }

  button:hover {
    cursor: pointer;
  }

  iframe {
    border: none !important;
  }

  .txt1 {
    font-family: Poppins-Regular;
    font-size: 13px;
    line-height: 1.5;
    text-decoration: none;
    color: #000;
  }

  .txt2 {
    font-family: Poppins-Regular;
    font-size: 13px;
    line-height: 1.5;
    color: #666666;
    text-decoration: none;
  }

  .p-t-12 {
    padding-top: 12px;
  }

  .p-t-136 {
    padding: 60px 0px 35px 0px;
    margin-left: 130px;
  }

  .text-center {
    text-align: center;
  }

  .text-center a {
    margin: 0px;
    font-size: 10px;
  }

  .limiter {
    width: 100%;
    margin: 0 auto;
  }

  .login_getCode {
    background-color: #ff7f3f;
    height: 30px;
    width: 90px;
    font-size: 13px;
    line-height: 30px;
    border-radius: 5px;
    text-align: center;
    color: #ffffff;
  }

  /*------------------------------------------------*/

  .login-pic {
    width: 316px;
  }

  .login-pic img {
    max-width: 100%;
  }

  .symbol-input100 {
    font-size: 15px;
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
    align-items: center;
    position: absolute;
    border-radius: 25px;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding-left: 35px;
    pointer-events: none;
    color: #666666;
    -webkit-transition: all 0.4s;
    -o-transition: all 0.4s;
    -moz-transition: all 0.4s;
    transition: all 0.4s;
  }

  .symbol-input {
    font-size: 15px;
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
    align-items: center;
    position: absolute;
    border-radius: 25px;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding-left: 35px;
    pointer-events: none;
    color: #e6e6e6;

    -webkit-transition: all 0.4s;
    -o-transition: all 0.4s;
    -moz-transition: all 0.4s;
    transition: all 0.4s;
  }

  /* .input:focus + .focus-input + .symbol-input {
  color: #ffe14e;
  padding-left: 28px;
} */

  /* 协议 */
  .agrea_box {
    width: 260px;
    display: flex;
    align-items: center;
    justify-content: center;
    float: right;
  }

  .agrea_text {
    font-size: 10px;
    margin-left: 0px;
    color: #ccc;
  }

  .agrea_text a {
    color: #ff7226;
  }

  /*----------------------------------------------*/
  .login-form {
    width: 335px;
  }

  .login-form-title {
    text-align: center;
    width: 100%;
    display: block;
    font-size: 20px;
    font-weight: 800;
    margin-top: 30px;
    margin-bottom: 30px;
    color: #ccc;
  }

  /*---------------------------------------------*/
  .wrap-input {
    position: relative;
    width: 335px;
    z-index: 1;
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 42px;
    border-radius: 5px;
    background: #000;
    border-radius: 21px;
    background: #000;
    border: 1px solid #f9761f;
  }


  .wrap-div {
    width: 80px;
    line-height: 1.5;
    font-size: 15px;
    padding-right: 10px;
    text-align: right;
    color: #727272;
    font-weight: 400;
  }

  .login_img {
    width: 28px;
    height: 28px;
    margin: 0px 0px 0px 14px;
  }

  .input {
    font-family: Poppins-Medium;
    font-size: 15px;
    line-height: 1.5;
    color: #fff;
    display: block;
    width: 255px;
    height: 100%;
    background-color: transparent;
    border: 0px;
    border-radius: 5px;
    padding: 0 10px 0 10px;
  }

  /* 按钮 */
  .container-login-form-btn {
    width: 100%;
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    padding-top: 20px;
  }

  .login-form-btn {
    font-family: Montserrat-Bold;
    font-size: 15px;
    line-height: 1.5;
    color: #fff;
    text-transform: uppercase;
    width: 100%;
    height: 42px;
    border-radius: 50px;
    background: -webkit-linear-gradient(-135deg, #ff7226, #ff9d68);
    background: -o-linear-gradient(-135deg, #ff7226, #ff9d68);
    background: -moz-linear-gradient(-135deg, #ff7226, #ff9d68);
    background: linear-gradient(-135deg, #ff7226, #ff9d68);
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 25px;

    -webkit-transition: all 0.4s;
    -o-transition: all 0.4s;
    -moz-transition: all 0.4s;
    transition: all 0.4s;
  }

  /* .login-form-btn:hover {
    background: #333333;
  } */

  .el-checkbox__input {
    margin-top: 50px;
  }

  div>>>.el-checkbox__label {
    font-size: 12px;
    margin-top: 30px;
  }

  div>>>.el-checkbox__inner {
    border-radius: 50%;
    margin-right: 5px;
    border-color: #ff7f3f;
  }

  div>>>.el-checkbox__input.is-checked .el-checkbox__inner,
  .el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background-color: #ff7f3f;
    border-color: #ff7f3f;
  }

  div>>>.el-checkbox__input.is-focus .el-checkbox__inner {
    border-color: #ff7f3f;
  }

  div>>>.el-checkbox__inner:hover {
    border-color: #ff7f3f;
  }

</style>
